﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using TAS;

namespace ProbeStation
{
    class CMEFutureData
    {
        FileStream file = null;
        StreamReader sr = null;

        public bool EndofFile = false;
        public FixMessageEntity fixMessageEntity = new FixMessageEntity();

        public void Initialize(string filename)
        {
            file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
            sr = new StreamReader(file);           
        }

        public FixMessageEntity ReadData()
        {
            try
            {
                if (EndofFile == false)
                {
                    if (fixMessageEntity != null)
                    {
                        fixMessageEntity = null;
                        fixMessageEntity = new FixMessageEntity();
                    }

                    string data = sr.ReadLine();

                    if (data != null)
                    {
                        fixMessageEntity.ParseMessage(data);
                        return fixMessageEntity;
                    }
                    else
                    {
                        EndofFile = true;
                        return null;
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            return null;
        }

        public void Close()
        {
            sr.Close();
            file.Close();
        }
    }
}
